var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    istokenPop: false,//判断是否等了
    total: 0,
    widthLine: 0,


    slideList: []
  },
  

  loginCode() {

    var _this = this
    this.setData({
      istokenPop: false
    })
  
    wx.navigateTo({
      url: '/package/juanshu/pages/buyBook/buyBook?wasActivities=1',
    })

  },

  getList () {

    var params = {
      page: 1,
      size: 5
    }
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/order/donate/donate/goto/list ',
      method: 'POST',
      data: params,
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
      },
      success: (res) => {
        
      }
    })
  },

  // gethasNum () {
  //   wx.request({
  //     url: '',
  //   })
  // },


  goHuodongto () {
    if (wx.getStorageSync('token') == '') {
      this.setData({
        istokenPop: true
      })
      return
    }
    wx.navigateTo({
      url: '/package/juanshu/pages/buyBook/buyBook?wasActivities=1',
    })
  },


  // 查询已筹多少本

  getBooknum () {

var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/order/donate/findDonateBookNum',
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
      },
      success: (res)=>{
        if (res.data.code==200) {
          _this.setData({
            total: res.data.data,
            widthLine: ((res.data.data / 3000) * 100).toFixed(2) < 1 ? 4 : ((res.data.data / 3000) * 100).toFixed(2)  
          })
        }
      }
    })
  },


  // 查询播报

  getSlide () {
    var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/user/global/activDonate',
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
      },
      success: (res)=>{
        if (res.data.code == 200) {


          for (var i = 0;i< res.data.data.length;i++) {
            if (res.data.data[i].donaterName.length>5) {
              res.data.data[i].donaterName = res.data.data[i].donaterName.substring(0,5) + '..'
            }
          }
          _this.setData({
            slideList: res.data.data
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon:'none'
          })
        }
      }
    })
  },


  // getList () {

    
  //   wx.request({
  //     url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/user/global/donate/auth',

  //   })
  // },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.getList()

    this.getSlide()
    this.getBooknum()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})